<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
$chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
$chk->checkShow3dPage();
$g_betname_3or5 = judge_type($gametype, true);
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
if ($chkGametype == 3)
{
    include_once( "class/function_3d.php" );
    include_once( "class_5h/RateConfig_5h.php" );
    $RateConfig_3d = new RateConfig_5h($gametype);
    $_5hFlag = true;
    $numGroup = array(9, 10, 11, 12, 13, 14);
}
else
{
    include_once( "class/function_3d.php" );
    include_once( "class_3d/RateConfig_3d.php" );
    $RateConfig_3d = new RateConfig_3d($gametype);
    $_5hFlag = false;
    $numGroup = array();
}
$rateNum = 3;
$num = getvar("num");
$bettype = getvar("bettype");
$subid = intval(getvar("subid"));
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$showType = getvar("showType");
$lid = getvar("lid");
$lid = $lid == "" ? "" : intval($lid);
$xyid = intval(getvar("xyid"));
$xyidStr = "";
if ($bettype !== "")
{
    $bettype = intval($bettype);
    $betsubid = "{$bettype}_{$subid}";
    if ($_5hFlag && in_array($bettype, $g_betXYArr[$gametype]) && in_array($xyid, array(1, 2)))
    {
        $xyidStr = " AND xyid = {$xyid} ";
    }
}
$dateS = getvar("dates");
$dateE = getvar("datee");
$postTime = $conf->get("paper_post_bet");
$today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
if ($dateS == "" || $dateE == "" || !is_date($dateS) || !is_date($dateE))
{
    $dateS = $today;
    $dateE = $today;
}
if ($dateS == $dateE && $dateE == $today)
{
    $x = "";
}
else
{
    $x = "x";
}
$aclID = getvar("ACLID");
if ($aclID == "")
{
    exit();
}
else
{
    $theID = $aclID;
    $theUser = get_user($theID);
    $theACL = $theUser['acl'];
}
if ($curruser['acl'] < $theACL)
{
    exit("error 1");
}
if ($theACL == "255")
{
    $showPercentACL = "255";
    $showPercentC = "r5";
}
else if ($theACL == "5")
{
    $showPercentACL = "255";
    $showPercentC = "r5";
}
else
{
    $showPercentACL = $theACL + 1;
    $showPercentC = "c" . $showPercentACL;
}
$betTitle = "";
if ($num != "all" && !$RateConfig_3d->checkBetNumber($bettype, $num))
{
    if (in_array($bettype, $numGroup))
    {
        $numGroupArr = explode(",", $num);
        $numGroupArrNum = count($numGroupArr);
        if ($numGroupArrNum != count(array_unique($numGroupArr)))
        {
            $ui->showErrorPage("错误的内容-1");
            exit();
        }
        if ($numGroupArrNum != count(array_intersect($RateConfig_3d->getBetTypeNumber($bettype), $numGroupArr)))
        {
            $ui->showErrorPage("错误的内容-2");
            exit();
        }
    }
    else
    {
        $ui->showErrorPage("错误的内容-3");
        exit();
    }
}
if ($bettype !== "" && !isset($g_betname_3or5[$bettype . "_" . $subid]))
{
    $ui->showErrorPage("错误的值");
    exit();
}
else if ($bettype !== "" && isset($g_betname_3or5[$bettype . "_" . $subid]))
{
    $betTitle = ":: " . $g_betname_3or5[$bettype . "_" . $subid];
}
$timeStart = strtotime($dateS . " 00:00:00");
$timeEnd = strtotime($dateE . " 23:59:59");
$sqlNum = $xyidStr;
if ($num != "all" && $num != "")
{
    if ($_5hFlag)
    {
        $sqlNum = " AND a.numbers = '{$num}'";
    }
    else
    {
        switch ($bettype)
        {
            case "24" :
            case "25" :
            case "26" :
            case "27" :
            case "28" :
            case "30" :
            case "31" :
            case "32" :
            case "33" :
            case "34" :
                $sqlNum = " AND a.numbers LIKE '%" . $num . "%'";
                break;
            case "35" :
                $numArr = $RateConfig_3d->mystr_split($num, 1);
                $sqlNum = " AND a.numbers LIKE '%" . $numArr[0] . "%,%" . $numArr[1] . "%,%" . $numArr[2] . "%'";
                break;
            default :
                $sqlNum = " AND a.numbers='" . $num . "'";
                break;
        }
    }
}
$backType = "";
$totalSql = "";
$betRType = intval(getvar("betRType"));
switch ($betRType)
{
    case 1 :
        $rameSQLStr2 = "AND a.rame = 9 AND (CASE a.acl WHEN 2 THEN (a.b2 - a.a2) WHEN 3 THEN (a.b3 - a.a3) WHEN 4 THEN (a.b4 - a.a4) WHEN 5 THEN (a.b5 - a.a5) ELSE 0 END) <= 0 ";
        $whereRameSQLStrAll = " AND a.rame = 9 AND (CASE a.acl WHEN 2 THEN (a.b2 - a.a2) WHEN 3 THEN (a.b3 - a.a3) WHEN 4 THEN (a.b4 - a.a4) WHEN 5 THEN (a.b5 - a.a5) ELSE 0 END) <= 0 ";
        $rameTitleStr = " 选项:上缴";
        break;
    case 2 :
        $rameSQLStr2 = "AND a.rame = 9 AND (CASE a.acl WHEN 2 THEN (a.b2 - a.a2) WHEN 3 THEN (a.b3 - a.a3) WHEN 4 THEN (a.b4 - a.a4) WHEN 5 THEN (a.b5 - a.a5) ELSE 0 END) > 0 ";
        $whereRameSQLStrAll = " AND a.rame = 9 AND (CASE a.acl WHEN 2 THEN (a.b2 - a.a2) WHEN 3 THEN (a.b3 - a.a3) WHEN 4 THEN (a.b4 - a.a4) WHEN 5 THEN (a.b5 - a.a5) ELSE 0 END) > 0 ";
        $rameTitleStr = " 选项:得分";
        break;
    default :
        $rameSQLStr2 = "";
        $whereRameSQLStrAll = " AND a.rame IN (0,9) ";
        $rameTitleStr = " 选项:全部";
        break;
}
switch ($theACL)
{
    case "255" :
        if ($showType == "0")
        {
            exit("error 1");
        }
        else
        {
            $showtitle = "{$tblName} 收飞清单 {$betTitle} {$rameTitleStr} {$dateS}~{$dateE}";
            $sql = "SELECT a.*, b.account,c.round, c.open FROM {$x}bet2_{$tbl} a";
            $sql .= " LEFT JOIN k_user b ON (a.user_id = b.id)";
            $sql .= " LEFT JOIN lotto_{$tbl} c ON (a.lotto_id = c.id)";
            if ($lid == "")
            {
                $sql .= " WHERE (c.open BETWEEN '{$dateS}' AND '{$dateE}')";
            }
            else
            {
                $sql .= " WHERE a.lotto_id={$lid} ";
            }
            $sql .= " {$rameSQLStr2} {$sqlNum}";
            $totalSql = "SELECT count(a.amount), sum(a.amount)";
            $totalSql .= " ,sum(CASE WHEN a.acl =2 THEN a.a2 WHEN a.acl =3 THEN a.a3 WHEN a.acl =4 THEN a.a4 WHEN a.acl =5 THEN a.a5 ELSE 0 END)";
            $totalSql .= " ,sum(CASE WHEN a.acl =2 THEN a.b2 WHEN a.acl =3 THEN a.b3 WHEN a.acl =4 THEN a.b4 WHEN a.acl =5 THEN a.b5 ELSE 0 END)";
            $totalSql .= " ,sum(a.amount*percent{$showPercentACL}/100)";
            $totalSql .= " ,sum(a.{$showPercentC})";
            $totalSql .= " FROM {$x}bet2_{$tbl} a";
            $totalSql .= " LEFT JOIN k_user b ON (a.user_id = b.id)";
            $totalSql .= " LEFT JOIN lotto_{$tbl} c ON (a.lotto_id = c.id)";
            if ($lid == "")
            {
                $totalSql .= " WHERE (c.open BETWEEN '" . $dateS . "' AND '" . $dateE . "')";
            }
            else
            {
                $totalSql .= " WHERE a.lotto_id = {$lid}";
            }
            $totalSql .= " {$whereRameSQLStrAll} {$sqlNum}";
        }
        break;
    default :
        if ($showType == "0")
        {
            exit("error 1");
        }
        else
        {
            $showtitle = "{$tblName} 收飞清单 {$betTitle} {$rameTitleStr} {$dateS}~{$dateE}";
            $sql = "SELECT a.*, b.account,c.round, c.open FROM {$x}bet2_{$tbl} a";
            $sql .= " LEFT JOIN k_user b ON (a.user_id = b.id)";
            $sql .= " LEFT JOIN lotto_{$tbl} c ON (a.lotto_id = c.id)";
            if ($lid == "")
            {
                $sql .= " WHERE (c.open BETWEEN '" . $dateS . "' AND '" . $dateE . "')";
            }
            else
            {
                $sql .= " WHERE a.lotto_id={$lid} ";
            }
            $sql .= " {$rameSQLStr2}";
            if ($theACL == 2)
            {
                $sql .= " AND user_id =" . $theID . $sqlNum;
            }
            else
            {
                $sql .= " AND uperid" . $theACL . " =" . $theID . $sqlNum;
            }
            $totalSql = "SELECT count(a.amount), sum(a.amount)";
            $totalSql .= " ,sum(CASE WHEN a.acl =2 THEN a.a2 WHEN a.acl =3 THEN a.a3 WHEN a.acl =4 THEN a.a4 WHEN a.acl =5 THEN a.a5 ELSE 0 END)";
            $totalSql .= " ,sum(CASE WHEN a.acl =2 THEN a.b2 WHEN a.acl =3 THEN a.b3 WHEN a.acl =4 THEN a.b4 WHEN a.acl =5 THEN a.b5 ELSE 0 END)";
            $totalSql .= " ,sum(a.amount*percent{$showPercentACL}/100)";
            $totalSql .= " ,sum(a.{$showPercentC})";
            $totalSql .= " FROM {$x}bet2_{$tbl} a";
            $totalSql .= " LEFT JOIN k_user b ON (a.user_id = b.id)";
            $totalSql .= " LEFT JOIN lotto_{$tbl} c ON (a.lotto_id = c.id)";
            if ($lid == "")
            {
                $totalSql .= " WHERE (c.open BETWEEN '" . $dateS . "' AND '" . $dateE . "')";
            }
            else
            {
                $totalSql .= " WHERE a.lotto_id = {$lid}";
            }
            $totalSql .= " {$whereRameSQLStrAll}";
            if ($theACL == 2)
            {
                $totalSql .= " AND user_id =" . $theID . $sqlNum;
            }
            else
            {
                $totalSql .= " AND uperid" . $theACL . " =" . $theID . $sqlNum;
            }
        }
        break;
}
if ($bettype !== "")
{
    $sql .= " AND bettype =" . $bettype . " AND subid =" . $subid;
    $totalSql .= " AND bettype =" . $bettype . " AND subid =" . $subid;
}
$rs = getdb($sql, $page, 20);
$totalrecords = $rs->totalrecords;
$littleNum = 0;
$littleAmount = 0;
$littleBack = 0;
$littleB1 = 0;
$littlePercentAmount = 0;
$littlePercentD = 0;
$ui->header();
echo title("{$tblName} 收飞清单", "<a href=\"javascript:window.print()\">列印</a>&nbsp;|&nbsp;<a href=\"javascript:history.back();\">回上一页</a>", "900");
echo "<br />";
echo "<table width=900 border=1 cellpadding=3 cellspacing=0>";
echo "<caption class=\"title0 bgImg_{$gametype}\" style='font-size:14px;font-weight:900'>" . $showtitle . "</caption>";
echo "<tr class=\"colorBtn01 clrBrd_{$gametype}\" align=center><td nowrap>单号 / 时间</td><td nowrap>管理员 / 退水</td><td nowrap> 期数 / 开奖日期</td><td nowrap>下注内容</td><td nowrap>下注金额</td><td nowrap>赔率</td><td nowrap>退水</td><td nowrap>结果</td>";
echo "<td nowrap>占成</td>";
echo "<td nowrap>占成额</td>";
echo "<td nowrap>占成结果</td>";
echo "<td nowrap>备注</td></tr>";
while (!$rs->eof)
{
    echo "<tr class=\"td2\">";
    echo "<td nowrap><font color=\"green\">" . $rs->f['id'] . "</font>&nbsp;&nbsp;" . date("m-d H:i:s", $rs->f['createtime']) . "</td>";
    switch ($rs->f['acl'])
    {
        case "255" :
            $backType = "back5";
            $backRsType = "a5";
            break;
        default :
            $backType = "back" . $rs->f['acl'];
            $backRsType = "a" . $rs->f['acl'];
            $backRsTypeB = "b" . $rs->f['acl'];
            break;
    }
    echo "<td nowrap>" . $rs->f['account'] . "&nbsp;&nbsp;<font color=\"green\">" . round(100 - $rs->f[$backType], $rateNum) . "</font></td>";
    echo "<td nowrap>" . $rs->f['round'] . "期&nbsp;<font color=\"green\">" . $rs->f['open'] . "</font></td>";
    echo "<td nowrap>";
    if ($_5hFlag)
    {
        echo "<font class='colorXY'>" . $RateConfig_3d->xyidTitle[$rs->f['xyid']] . "</font>";
    }
    echo "【" . $g_betname_3or5[$rs->f['bettype'] . "_" . $rs->f['subid']] . "】&nbsp;" . $rs->f['line_nums'] . "</td>";
    if (20000 < $rs->f['amount'])
    {
        $color = "alert2";
    }
    else if (10000 < $rs->f['amount'])
    {
        $color = "alert1";
    }
    else
    {
        $color = "";
    }
    echo "<td nowrap align=\"right\" class=\"" . $color . "\">" . $rs->f['amount'] . "</td>";
    echo "<td nowrap align=\"right\">" . floatval($rs->f['rate']) . "</td>";
    echo "<td nowrap align=\"right\">" . round($rs->f[$backRsType], 2) . "</td>";
    echo "<td nowrap align=\"right\">" . say_numbercolor($rs->f[$backRsTypeB], $rateNum) . "</td>";
    $tempA = 0;
    $tempB = 0;
    $tempC = 0;
    if ($rs->f['rame'] == 1)
    {
        $note = "<font color=red>- 逾时 -</font>";
    }
    else if ($rs->f['rame'] == 2)
    {
        $note = "<font color=red>- 取消 -</font>";
    }
    else if ($rs->f['rame'] == 3)
    {
        $note = "<font color=red>- 异常 -</font>";
    }
    else
    {
        $note = "";
        $littleNum += 1;
        $littleAmount += $rs->f['amount'];
        $littleBack += $rs->f[$backRsType];
        $littleB1 += $rs->f[$backRsTypeB];
        $littlePercentAmountTemp = $rs->f['amount'] * $rs->f["percent" . $showPercentACL] / 100;
        $littlePercentAmount += $littlePercentAmountTemp;
        $littlePercentD += $rs->f[$showPercentC];
        $tempA = $rs->f["percent" . $showPercentACL];
        $tempB = $littlePercentAmountTemp;
        $tempC = say_numbercolor($rs->f[$showPercentC], 2);
    }
    echo "<td nowrap align=\"right\">" . $tempA . "</td>";
    echo "<td nowrap align=\"right\">" . $tempB . "</td>";
    echo "<td nowrap align=\"right\">" . $tempC . "</td>";
    if ($rs->f['betmode'] == 0)
    {
        $note .= "<font color=blue>#</font>";
    }
    if (chkBet_peace(array("a1" => $rs->f[$backRsType], "b1" => $rs->f[$backRsTypeB], "rame" => $rs->f['rame'])))
    {
        $note .= " <font class='betpeace'>和局</font>";
    }
    if ($curruser['acl'] == 255)
    {
        $note .= floatval($rs->f['rate5']) ? "<font class=\"c5\" color=\"red\">[" . floatval($rs->f['rate5']) . "]</font>" : "";
    }
    echo "<td nowrap>" . $note . "</td>";
    echo "</tr>";
    $rs->movenext();
}
if (1 < $rs->totalpages)
{
    echo "<tr align=\"right\" class=\"td1\"><td colspan=\"4\">小计 " . $littleNum . " 笔</td><td>" . $littleAmount . "</td><td>--</td><td>" . round($littleBack, 2) . "</td><td>" . say_numbercolor($littleB1, $rateNum) . "</td>";
    echo "<td nowrap align=\"right\">--</td>";
    echo "<td nowrap align=\"right\">" . $littlePercentAmount . "</td>";
    echo "<td nowrap align=\"right\">" . say_numbercolor($littlePercentD, $rateNum) . "</td>";
    echo "<td>&nbsp;</td></tr>";
}
$totalRs = getdb($totalSql);
if (!$totalRs->eof)
{
    echo "<tr align=\"right\" class=\"td3\"><td colspan=\"4\">总计 " . $totalRs->f[0] . " 笔</td><td>" . $totalRs->f[1] . "</td><td>--</td><td>" . round($totalRs->f[2], 2) . "</td><td>" . say_numbercolor($totalRs->f[3], $rateNum) . "</td>";
    echo "<td nowrap align=\"right\">--</td>";
    echo "<td nowrap align=\"right\">" . round($totalRs->f[4]) . "</td>";
    echo "<td nowrap align=\"right\">" . say_numbercolor($totalRs->f[5], $rateNum) . "</td>";
    echo "<td>&nbsp;</td></tr>";
}
echo "<tr><td class=\"colorBtn01 clrBrd_{$gametype }\" colspan=\"12\">" . $rs->pagelink() . "</td></tr>";
echo "</table>";
echo "<p>备注：有&nbsp;<font color=blue>#</font>&nbsp;表示手动走飞</p>";
echo "<script> \r\n$(\"tbody tr[class=td2]\").hover(\r\n  function() {\$(this).addClass(\"trover\");}\r\n  , function() {\$(this).removeClass(\"trover\");}\r\n);\r\n</script>  \r\n";
$ui->footer();
?>